package com.sdhs.analyze.schedule;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.sdhs.analyze.bean.DicGantryTrade;
import com.sdhs.analyze.bean.DicSpecialType;
import com.sdhs.analyze.bean.monitorinfo.CameraHourSuccessRate;
import com.sdhs.analyze.bean.monitorinfo.CameraSuccessRate;
import com.sdhs.analyze.bean.monitorinfo.DataTransInfo;
import com.sdhs.analyze.bean.monitorinfo.RsuHourSuccessRate;
import com.sdhs.analyze.bean.monitorinfo.RsuSuccessRate;
import com.sdhs.analyze.bean.monitorinfo.SuccessRateUnit;
import com.sdhs.analyze.bean.operationdata.MinuteSum;
import com.sdhs.analyze.bean.operationdata.TradeDaySum;
import com.sdhs.analyze.bean.operationdata.TradeHourSum;
import com.sdhs.analyze.common.BizConstants;
import com.sdhs.analyze.service.monitor.DicServiceNew;
import com.sdhs.analyze.utils.RedisUtil;
import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;


@Component
public class GantryTradeTask {
    private static Logger logger = LoggerFactory.getLogger(GantryTradeTask.class);
    SimpleDateFormat sdfDay = new SimpleDateFormat("yyyyMMdd");
    SimpleDateFormat sdfHour = new SimpleDateFormat("HH");
    SimpleDateFormat sdfMinute = new SimpleDateFormat("HHmm");

    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private DicServiceNew dicService;

    /**
     * 计费扣费交易汇总
     *
     * @param record
     * @throws Exception
     */
    @KafkaListener(topics = "ETCTU")
    public void tradeTask(String record) throws Exception {
        DicGantryTrade dicGantryTrade = JSONObject.parseObject(record, DicGantryTrade.class);
        Integer workMode = dicGantryTrade.getWorkMode();
        if (workMode != null && workMode == 4) {
            logger.error("工作模式为4的不做处理！");
            return;
        }
        /* 运营数据汇总 */
        operationDataSum(dicGantryTrade);
        /* 运行监测 */
        monitor(dicGantryTrade);
    }

    /**
     * 日车流量通行费汇总
     *
     * @param gantryId
     * @param transDay
     * @param vc
     * @param fee
     * @param mediaType
     * @param obuSign
     */
    private void daySum(String gantryId, String transDay, Integer vc, Long fee, Integer mediaType, Integer obuSign) {
        /* 获取日车流量通行费汇总 按交易日期 */
        //key format: gantry_sum_trade_day:gantryId:yyyyMMdd
        String daySumKey = BizConstants.REDIS_KEY_PRE_GANTRY_SUM_TRADE_DAY + BizConstants.ORG_TYPE_GANTRY_FRONT + ":" + gantryId + ":" + transDay;
        String jsonString = redisUtil.get(daySumKey);
        TradeDaySum tradeDaySum;
        if (jsonString == null) {
            tradeDaySum = new TradeDaySum(gantryId, BizConstants.ORG_TYPE_GANTRY_FRONT, transDay);
        } else {
            tradeDaySum = JSONObject.parseObject(jsonString, TradeDaySum.class);
        }

        /* 分车型汇总 */
        Long oldCnt = tradeDaySum.getVcCnt().get(vc);
        if (oldCnt == null) {
            oldCnt = Long.valueOf(0);
        }
        tradeDaySum.getVcCnt().put(vc, oldCnt + 1);

        Long oldFee = tradeDaySum.getVcFee().get(vc);
        if (tradeDaySum.getVcFee().get(vc) == null) {
            oldFee = Long.valueOf(0);
        }
        tradeDaySum.getVcFee().put(vc, oldFee + fee);

        /* 分通行介质汇总 */
        if (mediaType == BizConstants.MEDIA_TYPE_CPC) {
            tradeDaySum.setCpcCnt(tradeDaySum.getCpcCnt() + 1);
            tradeDaySum.setCpcFee(tradeDaySum.getCpcFee() + fee);
        } else if (mediaType == BizConstants.MEDIA_TYPE_OBU) {
            if (obuSign == BizConstants.OBU_SIGN_SINGLE) {
                tradeDaySum.setsOBUCnt(tradeDaySum.getsOBUCnt() + 1);
                tradeDaySum.setsOBUFee(tradeDaySum.getsOBUFee() + fee);
            } else {
                tradeDaySum.setdOBUCnt(tradeDaySum.getdOBUCnt() + 1);
                tradeDaySum.setdOBUFee(tradeDaySum.getdOBUFee() + fee);
            }
        }

        /* 更新缓存 */
        redisUtil.setEx(daySumKey, JSONObject.toJSONString(tradeDaySum), 1, TimeUnit.DAYS);
    }

    /**
     * 小时车流量汇总
     *
     * @param gantryId
     * @param transDay
     * @param transHour
     */
    private void hourSum(String gantryId, String transDay, String transHour) {
        /* 获取小时车流量汇总 按交易日期小时 */
        //key format: gantry_sum_trade_hour_rsu:gantryId:yyyyMMdd:HH
        String hourSumKey = BizConstants.REDIS_KEY_PRE_GANTRY_SUM_TRADE_HOUR_RSU + gantryId + ":" + transDay + ":" + transHour;
        String jsonString = redisUtil.get(hourSumKey);
        TradeHourSum tradeHourSum;
        if (jsonString == null) {
            tradeHourSum = new TradeHourSum(gantryId, BizConstants.ORG_TYPE_GANTRY_FRONT, transDay, transHour);
        } else {
            tradeHourSum = JSON.parseObject(jsonString, TradeHourSum.class);
        }

        tradeHourSum.setCnt(tradeHourSum.getCnt() + 1);

        /* 更新缓存 */
        redisUtil.setEx(hourSumKey, JSONObject.toJSONString(tradeHourSum), 1, TimeUnit.DAYS);
    }

    /**
     * 分钟汇总
     *
     * @param gantryId
     * @param nowDay
     * @param nowMinute
     */
    private void minuteSum(String gantryId, String nowDay, String nowMinute) {
        /* 获取分钟数据传输量汇总 */
        //key format: gantry_sum_data_minute_rsu:gantryId:yyyyMMdd:HHmm
        String minuteSumKey = BizConstants.REDIS_KEY_PRE_GANTRY_SUM_DATA_MINUTE_RSU + gantryId + ":" + nowDay + ":" + nowMinute;
        String jsonString = redisUtil.get(minuteSumKey);
        MinuteSum dataMinuteSum;
        if (jsonString == null) {
            dataMinuteSum = new MinuteSum(gantryId, BizConstants.ORG_TYPE_GANTRY_FRONT, nowDay, nowMinute);
        } else {
            dataMinuteSum = JSON.parseObject(jsonString, MinuteSum.class);
        }

        dataMinuteSum.setCnt(dataMinuteSum.getCnt() + 1);

        /* 更新缓存 */
        redisUtil.setEx(minuteSumKey, JSONObject.toJSONString(dataMinuteSum), 1, TimeUnit.HOURS);
    }

    /**
     * 牌识匹配率监测
     *
     * @param dicGantryTrade
     */
    private void cameraSuccessRateMonitor(DicGantryTrade dicGantryTrade) {
        String transDay = sdfDay.format(dicGantryTrade.getTransTime());
        String gantryId = dicGantryTrade.getGantryId();
        /* 牌识匹配率监测：仅汇交易成功且车牌有效的数据 */
        if (dicGantryTrade.getTradeResult() != 0 || dicGantryTrade.getVehiclePlate().equals("默A00000_9")) {
            return;
        }
        /* 仅汇总交易成功的 */
        /* 牌识匹配率监测 */
        //key format: gantry_camera_success_rate:3:gantryId:yyyyMMdd
        String cameraSuccessRateKey = BizConstants.REDIS_KEY_PRE_GANTRY_CAMERA_SUCCESS_RATE
                + BizConstants.ORG_TYPE_GANTRY_FRONT + ":" + gantryId + ":" + transDay;
        String jsonString = redisUtil.get(cameraSuccessRateKey);
        CameraSuccessRate cameraSuccessRate = null;
        if (jsonString == null) {
            cameraSuccessRate = new CameraSuccessRate(gantryId, BizConstants.ORG_TYPE_GANTRY_FRONT, transDay);
        } else {
            cameraSuccessRate = JSON.parseObject(jsonString, CameraSuccessRate.class);
        }
        /* 匹配成功 非匹配失败的都算作成功 20200221 */
        if (dicGantryTrade.getMatchStatus() != 2) {
            cameraSuccessRate.setSuccessCnt(cameraSuccessRate.getSuccessCnt() + 1);
        } else {
            cameraSuccessRate.setFailCnt(cameraSuccessRate.getFailCnt() + 1);
        }

        /* 更新缓存 */
        redisUtil.setEx(cameraSuccessRateKey, JSONObject.toJSONString(cameraSuccessRate), 1, TimeUnit.DAYS);
    }

    /**
     * 小时牌识匹配率监测
     *
     * @param dicGantryTrade
     */
    private void cameraHourSuccessRateMonitor(DicGantryTrade dicGantryTrade) {
        String transDay = sdfDay.format(dicGantryTrade.getTransTime());
        String transHour = sdfHour.format(dicGantryTrade.getTransTime());
        String gantryId = dicGantryTrade.getGantryId();
        /* 牌识匹配率监测：仅汇交易成功且车牌有效的数据 */
        if (dicGantryTrade.getTradeResult() != 0 || dicGantryTrade.getVehiclePlate().equals("默A00000_9")) {
            return;
        }
        /* 仅汇总交易成功的 */
        /* 牌识匹配率监测 */
        String cameraHourSuccessRateKey = BizConstants.REDIS_KEY_PRE_GANTRY_CAMERA_HOUR_SUCCESS_RATE
                + BizConstants.ORG_TYPE_GANTRY_FRONT + ":" + gantryId + ":" + transDay + ":" + transHour;
        String jsonString = redisUtil.get(cameraHourSuccessRateKey);
        CameraHourSuccessRate cameraHourSuccessRate = null;
        if (jsonString == null) {
            cameraHourSuccessRate = new CameraHourSuccessRate(gantryId, BizConstants.ORG_TYPE_GANTRY_FRONT, transDay, transHour);
        } else {
            cameraHourSuccessRate = JSON.parseObject(jsonString, CameraHourSuccessRate.class);
        }
        /* 匹配成功 非匹配失败的都算作成功 20200221 */
        if (dicGantryTrade.getMatchStatus() != 2) {
            cameraHourSuccessRate.setSuccessCnt(cameraHourSuccessRate.getSuccessCnt() + 1);
        } else {
            cameraHourSuccessRate.setFailCnt(cameraHourSuccessRate.getFailCnt() + 1);
        }

        /* 更新缓存 */
        redisUtil.setEx(cameraHourSuccessRateKey, JSONObject.toJSONString(cameraHourSuccessRate), 1, TimeUnit.DAYS);
    }

    /**
     * rsu交易成功率监测
     *
     * @param dicGantryTrade
     */
    private void rsuSuccessRateMonitor(DicGantryTrade dicGantryTrade) {
        String transDay = sdfDay.format(dicGantryTrade.getTransTime());
        String gantryId = dicGantryTrade.getGantryId();

        String firstSpecialType = dicGantryTrade.getFirstSpecialType();

        if (firstSpecialType != null && firstSpecialType.equals("") == false && firstSpecialType.equals("0") == false) {

            Map<String, DicSpecialType> dicSpecialTypeMap = dicService.getStatedDicSpecialType();

            DicSpecialType tmpDicSpecialType = dicSpecialTypeMap.get(firstSpecialType);

            /* 不在统计范围内 */
            if (tmpDicSpecialType == null) {

                return;
            }
        }

//        if(specialType != null && (specialType.contains("101") ||
//                specialType.contains("102") ||
//                specialType.contains("103") ||
//                specialType.contains("106") ||
//                specialType.contains("110") ||
//                specialType.contains("118") ||
//                specialType.contains("119") ||
//                specialType.contains("130") ||
//                specialType.contains("135") ||
//                specialType.contains("136") ||
//                specialType.contains("137") ||
//                specialType.contains("185") ||
//                specialType.contains("186") ||
//                specialType.contains("193") ||
//                specialType.contains("195") ||
//                specialType.contains("198") ||
//                specialType.contains("154"))) {
//            return;
//        }
        /* 车牌无效的，不汇总 */
        if (dicGantryTrade.getVehiclePlate().equals("默A00000_9")) {
            return;
        }
        /* rsu交易成功率监测 */
        //key format: gantry_rsu_success_rate:3:gantryId:yyyyMMdd
        String rsuSuccessRateKey = BizConstants.REDIS_KEY_PRE_GANTRY_RSU_SUCCESS_RATE + BizConstants.ORG_TYPE_GANTRY_FRONT + ":" + gantryId + ":" + transDay;
        String jsonString = redisUtil.get(rsuSuccessRateKey);
        RsuSuccessRate rsuSuccessRate = null;
        if (jsonString == null) {
            rsuSuccessRate = new RsuSuccessRate(gantryId, BizConstants.ORG_TYPE_GANTRY_FRONT, sdfDay.format(dicGantryTrade.getTransTime()));
        } else {
            rsuSuccessRate = JSON.parseObject(jsonString, RsuSuccessRate.class);
        }
        /* 交易成功 */
        if (dicGantryTrade.getTradeResult() == 0) {
            rsuSuccessRate.setSuccessCnt(rsuSuccessRate.getSuccessCnt() + 1);

            /* 分设备汇总 */
            String deviceKey = gantryId + "|" + dicGantryTrade.getAntennaId();
            SuccessRateUnit unit = rsuSuccessRate.getDeviceSuccessRate().get(deviceKey);
            if (unit == null) {
                //nodeId nodeName
                unit = new SuccessRateUnit(deviceKey, "");
                rsuSuccessRate.getDeviceSuccessRate().put(deviceKey, unit);
            }
            unit.setSuccessCnt(unit.getSuccessCnt() + 1);
        } else {
            rsuSuccessRate.setFailCnt(rsuSuccessRate.getFailCnt() + 1);

            /* 分设备汇总 */
            String deviceKey = gantryId + "|" + dicGantryTrade.getAntennaId();
            SuccessRateUnit unit = rsuSuccessRate.getDeviceSuccessRate().get(deviceKey);
            if (unit == null) {
                //nodeId nodeName
                unit = new SuccessRateUnit(deviceKey, "");
                rsuSuccessRate.getDeviceSuccessRate().put(deviceKey, unit);
            }
            unit.setFailCnt(unit.getFailCnt() + 1);
        }

        /* 更新缓存 */
        redisUtil.setEx(rsuSuccessRateKey, JSONObject.toJSONString(rsuSuccessRate), 1, TimeUnit.DAYS);

    }

    /**
     * rsu交易成功率监测
     *
     * @param dicGantryTrade
     */
    private void rsuHourSuccessRateMonitor(DicGantryTrade dicGantryTrade) {
        String transDay = sdfDay.format(dicGantryTrade.getTransTime());
        String transHour = sdfHour.format(dicGantryTrade.getTransTime());
        Integer medaiType = dicGantryTrade.getMediaType();
        String gantryId = dicGantryTrade.getGantryId();

        String firstSpecialType = dicGantryTrade.getFirstSpecialType();

        if (firstSpecialType != null && firstSpecialType.equals("") == false && firstSpecialType.equals("0") == false) {

            Map<String, DicSpecialType> dicSpecialTypeMap = dicService.getStatedDicSpecialType();

            DicSpecialType tmpDicSpecialType = dicSpecialTypeMap.get(firstSpecialType);

            /* 不在统计范围内 */
            if (tmpDicSpecialType == null) {

                return;
            }
        }

//        if(specialType != null && (specialType.contains("101") ||
//                specialType.contains("102") ||
//                specialType.contains("103") ||
//                specialType.contains("106") ||
//                specialType.contains("110") ||
//                specialType.contains("118") ||
//                specialType.contains("119") ||
//                specialType.contains("130") ||
//                specialType.contains("135") ||
//                specialType.contains("136") ||
//                specialType.contains("137") ||
//                specialType.contains("185") ||
//                specialType.contains("186") ||
//                specialType.contains("193") ||
//                specialType.contains("195") ||
//                specialType.contains("198") ||
//                specialType.contains("154"))) {
//            return;
//        }
        /* 车牌无效的，不汇总 */
        if (dicGantryTrade.getVehiclePlate().equals("默A00000_9")) {
            return;
        }
        /* rsu小时交易成功率监测 */
        String rsuHourSuccessRateKey =
                BizConstants.REDIS_KEY_PRE_GANTRY_RSU_HOUR_SUCCESS_RATE +
                        BizConstants.ORG_TYPE_GANTRY_FRONT + ":" +
                        gantryId + ":" + transDay + ":" + transHour;
        String jsonString = redisUtil.get(rsuHourSuccessRateKey);
        RsuHourSuccessRate rsuHourSuccessRate = null;
        if (jsonString == null) {
            rsuHourSuccessRate =
                    new RsuHourSuccessRate(gantryId, BizConstants.ORG_TYPE_GANTRY_FRONT,
                            transDay, transHour);
        } else {
            rsuHourSuccessRate = JSON.parseObject(jsonString, RsuHourSuccessRate.class);
        }
        /* 交易成功 */
        if (dicGantryTrade.getTradeResult() == 0) {
            rsuHourSuccessRate.setSuccessCnt(rsuHourSuccessRate.getSuccessCnt() + 1);
            if (medaiType != null && medaiType == BizConstants.MEDIA_TYPE_OBU) {
                rsuHourSuccessRate.setEtcSuccessCnt(rsuHourSuccessRate.getEtcSuccessCnt() + 1);
            } else if (medaiType != null && medaiType == BizConstants.MEDIA_TYPE_CPC) {
                rsuHourSuccessRate.setCpcSuccessCnt(rsuHourSuccessRate.getCpcSuccessCnt() + 1);
            }
        }
        /* 交易失败 */
        else {
            rsuHourSuccessRate.setFailCnt(rsuHourSuccessRate.getFailCnt() + 1);
            if (medaiType != null && medaiType == BizConstants.MEDIA_TYPE_OBU) {
                rsuHourSuccessRate.setEtcFailCnt(rsuHourSuccessRate.getEtcFailCnt() + 1);
                /* 分特情汇总 */
                Map<String, Integer> etcSpecialTypeSumMap = rsuHourSuccessRate.getEtcSpecialTypeSum();
                if (etcSpecialTypeSumMap == null) {
                    etcSpecialTypeSumMap = new HashMap<>();
                    rsuHourSuccessRate.setEtcSpecialTypeSum(etcSpecialTypeSumMap);
                }
                if (etcSpecialTypeSumMap.get(firstSpecialType) == null) {
                    etcSpecialTypeSumMap.put(firstSpecialType, 1);
                } else {
                    etcSpecialTypeSumMap.put(firstSpecialType, etcSpecialTypeSumMap.get(firstSpecialType) + 1);
                }
            } else if (medaiType != null && medaiType == BizConstants.MEDIA_TYPE_CPC) {
                rsuHourSuccessRate.setCpcFailCnt(rsuHourSuccessRate.getCpcFailCnt() + 1);
                /* 分特情汇总 */
                Map<String, Integer> cpcSpecialTypeSumMap = rsuHourSuccessRate.getCpcSpecialTypeSum();
                if (cpcSpecialTypeSumMap == null) {
                    cpcSpecialTypeSumMap = new HashMap<>();
                    rsuHourSuccessRate.setCpcSpecialTypeSum(cpcSpecialTypeSumMap);
                }
                if (cpcSpecialTypeSumMap.get(firstSpecialType) == null) {
                    cpcSpecialTypeSumMap.put(firstSpecialType, 1);
                } else {
                    cpcSpecialTypeSumMap.put(firstSpecialType, cpcSpecialTypeSumMap.get(firstSpecialType) + 1);
                }
            }
        }

        /* 更新缓存 */
        redisUtil.setEx(rsuHourSuccessRateKey, JSONObject.toJSONString(rsuHourSuccessRate), 1, TimeUnit.DAYS);

    }

    /**
     * 数据传输监测
     *
     * @param dicGantryTrade
     */
    private void dataTransMonitor(DicGantryTrade dicGantryTrade, Date now) {
        Date transTime = dicGantryTrade.getTransTime();
        String gantryId = dicGantryTrade.getGantryId();
        /* 数据传输情况 */
        //key format: gantry_data_trans_info:gantryId:type
        String dataTransInfoRsuKey = BizConstants.REDIS_KEY_PRE_GANTRY_DATA_TRANS_INFO_RSU + gantryId;
        String jsonString = redisUtil.get(dataTransInfoRsuKey);
        DataTransInfo dataTransInfo = null;
        if (jsonString == null) {
            dataTransInfo = new DataTransInfo(gantryId, BizConstants.ORG_TYPE_GANTRY_FRONT, transTime);
        } else {
            dataTransInfo = JSON.parseObject(jsonString, DataTransInfo.class);
        }
        Date lastTime = dataTransInfo.getLastTime();
        if (transTime.getTime() < lastTime.getTime()) {
            return;
        }
        dataTransInfo.setDelay((now.getTime() - transTime.getTime()) / 1000);
        dataTransInfo.setLastTime(transTime);
        dataTransInfo.setLastChangeTime(now);
        /* 更新缓存 */
        redisUtil.setEx(dataTransInfoRsuKey, JSONObject.toJSONString(dataTransInfo), 365, TimeUnit.DAYS);
    }

    /**
     * 运行监测
     *
     * @param dicGantryTrade
     */
    private void monitor(DicGantryTrade dicGantryTrade) {

        Date now = new Date();

        String nowDay = sdfDay.format(now);

        Calendar calendar = Calendar.getInstance();

        /* 数据传输分钟汇总，仅汇总交易时间在48小时内的 */
        calendar.setTime(new Date());
        calendar.add(calendar.HOUR_OF_DAY, -48);
        if (dicGantryTrade.getTransTime().after(calendar.getTime())) {
            /* 数据传输监测 */
            logger.info("开始数据传输监测");
            dataTransMonitor(dicGantryTrade, now);
        }

        /* 成功率监测：仅汇总大于等于本日的数据且有效的数据 */
        if (sdfDay.format(dicGantryTrade.getTransTime()).compareTo(nowDay) >= 0) {
            logger.info("开始成功率监测");
            /* rsu交易成功率监测 */
            rsuSuccessRateMonitor(dicGantryTrade);

            /* 牌识匹配成功率监测 */
            cameraSuccessRateMonitor(dicGantryTrade);
        }
        /* 小时成功率监测：仅汇总24小时内且有效的数据 */
        calendar.setTime(now);
        calendar.add(calendar.HOUR_OF_DAY, -24);
        if (dicGantryTrade.getTransTime().after(calendar.getTime())) {
            logger.info("小时成功率监测");
            /* rsu小时交易成功率监测 */
            rsuHourSuccessRateMonitor(dicGantryTrade);

            /* 牌识小时匹配成功率监测 */
            cameraHourSuccessRateMonitor(dicGantryTrade);
        }
    }

    private void operationDataSum(DicGantryTrade dicGantryTrade) {
        /* 运营数据监测：仅汇总有效的数据 */
        if (dicGantryTrade.getTradeResult() == 0 || (dicGantryTrade.getTradeResult() == 1 && dicGantryTrade.getFeeCalcResult() == 0 && dicGantryTrade.getMediaType() != null && dicGantryTrade.getMediaType() == 1)) {
            String gantryId = dicGantryTrade.getGantryId();
            Date transTime = dicGantryTrade.getTransTime();
            /* 获取当前时间 */
            Date now = new Date();
            String nowDay = sdfDay.format(now);
            String nowMinute = sdfMinute.format(now);

            String transDay = sdfDay.format(transTime);
            String transHour = sdfHour.format(transTime);

            /* 分车型汇总 */
            Integer feeVehicleType = dicGantryTrade.getFeeVehicleType();
            Integer vc = dicGantryTrade.getVehicleType();
            Integer obuVc = dicGantryTrade.getOBUVehicleType();

            /* 判断计费车型是否合法 */
            if (ArrayUtils.contains(BizConstants.VC_CODE, feeVehicleType) == false) {

                if (ArrayUtils.contains(BizConstants.VC_CODE, vc) == false) {
                    /* 判断OBU车型是否合法 */
                    if (obuVc != null && ArrayUtils.contains(BizConstants.VC_CODE, obuVc) == true) {
                        feeVehicleType = obuVc;
                    } else {
                        feeVehicleType = 0;
                    }
                } else {
                    feeVehicleType = vc;
                }
            }


            /* OBU类型 */
            Integer obuSign = dicGantryTrade.getObuSign();

            /* 通行介质类型 */
            Integer mediaType = dicGantryTrade.getMediaType();

            /* 交易金额 */
            Long fee = dicGantryTrade.getFee();

            /* 日汇总：仅汇总本日且有效的数据 */
            if (sdfDay.format(transTime).equals(nowDay) == true) {
                daySum(gantryId, transDay, feeVehicleType, fee, mediaType, obuSign);
            }

            /* 小时汇总：仅汇总24小时内且有效的数据 */
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            calendar.add(calendar.HOUR_OF_DAY, -24);
            if (transTime.after(calendar.getTime())) {
                hourSum(gantryId, transDay, transHour);
            }

            /* 数据传输分钟汇总，仅汇总交易时间在48小时内的 */
            calendar.setTime(new Date());
            calendar.add(calendar.HOUR_OF_DAY, -48);
            if (transTime.after(calendar.getTime())) {
                minuteSum(gantryId, nowDay, nowMinute);
            }
        }
    }
}
